package com.lonely.common.utils.enums;

import cn.hutool.core.convert.Convert;
import com.lonely.common.core.domain.StatusInfo;
import com.lonely.common.enums.StatusEnumInterface;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author : 黄志标
 * @date: 2025/9/30 10:23
 * @description: 提取状态统计信息工具类
 */
public class ExtractStatusInfoUtil {


    /**
     * 提取状态信息
     *
     * @param statusTotals
     * @return
     */
    public static List<StatusInfo> extractStatusInfos(List<StatusInfo> statusTotals, StatusEnumInterface[] statusEnumInterfaces) {
        Map<String, Integer> existsStatusQuantityMap = Optional.ofNullable(statusTotals).orElse(new ArrayList<>()).stream().collect(Collectors.toMap(StatusInfo::getStatus, StatusInfo::getQuantity));

        // 编辑所有状态
        List<StatusInfo> statusInfos = new ArrayList<>();
        for (StatusEnumInterface statusEnumInterface : statusEnumInterfaces) {
            StatusInfo statusInfo = new StatusInfo();
            String status = Convert.toStr(statusEnumInterface.getStatus());
            statusInfo.setStatus(status);
            statusInfo.setStatusName(statusEnumInterface.getStatusName());
            statusInfo.setQuantity(existsStatusQuantityMap.getOrDefault(status, 0));
            statusInfos.add(statusInfo);
        }
        return statusInfos;
    }

}
